import { SkillInfoPanel } from "../SkillInfoPanel";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ModuleBg } from "../../common/ModuleBg";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { SkillDetailPanel } from "../career/SkillDetailPanel";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { SkillInfo } from "../../../model/SkillInfo";
import { SkillItem } from "../SkillItem";
import { Cache } from "../../../cache/Cache";
import { EGuildStructureType } from "../../../../../Message/Public/EGuildStructureType";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
//class SkillGuildInfoPanel
    
    export  class SkillGuildInfoPanel extends SkillInfoPanel
    {
        constructor()
        {
            super();
            this._skillName = new GLabel();
            this._skillLevel = new GLabel();
            this._buildLevel = new GLabel();
            this._conbuitTxt = new GLabel();
            this._info = new Object /* flash.text.TextField */();
            this._info = new Object /* flash.text.TextField */();
            this._info.selectable = false;
            this._info.textColor = 13026729;
            this._info.filters = [FilterConst.nameGlowFilter];
            this._info.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._info.width = 173;
            this._info.addEventListener(flash.events.TextEvent.LINK, this.onLearnedTxtLinkHandler);
            this._bg = new ModuleBg();
            this.createMainInfo();
            this.createConditionsInfo();
            addChild(this._bg);
            return;
        }

        /* internal  */onLearnedTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.OpenGuildWindow, 7));
            return;
        }

        /* internal  */createMainInfo(): void
        {
            this._bg.addItem(ResouceConst.getScaleBitmap(ImagesConst.DisabledBg), {"x": 4, "y": 4, "width": width - 8, "height": 50});
            this._bg.addItem(GlobalClass.getBitmap(ImagesConst.PackItemBg), {"x": 15, "y": 10});
            this._bg.addItem(this._skillName, {"x": 60, "y": 12, "width": 150, "height": 18, "styleName":"GLabel"});
            this._bg.addItem(this._skillLevel, {"x": 60, "y": 28, "width": 150, "height": 18, "styleName":"GLabel"});
            return;
        }

        /* internal  */createDetailInfo(): void
        {
            if (!this._detailPanel) 
            {
                this._detailPanel = new SkillDetailPanel();
            }
            if (!this._detailPanel.parent) 
            {
                this._bg.addItem(this._detailPanel, {"x": 4, "y": 62});
            }
            return;
        }

        /* internal  */createConditionsInfo(): void
        {
            this._bg.addItem(GlobalClass.getBitmap(ImagesConst.Line), {"x":-40, "y": 275});
            this._bg.addItem(new GLabel(), {"x": 80, "y": 293, "htmlText": HTMLUtil.addColor("<font size=\'14\'>" + Language.getString(20676) + "</font>", "#FFF72A"), "filters":[FilterConst.nameGlowFilter]});
            this._bg.addItem(new GLabel(), {"x": 4, "y": 315, "htmlText": HTMLUtil.addColor(Language.getString(57582) + "：", "#F5C767")});
            this._bg.addItem(new GLabel(), {"x": 4, "y": 335, "htmlText": HTMLUtil.addColor(Language.getString(57583) + "：", "#F5C767")});
            this._bg.addItem(this._buildLevel, {"x": 65, "y": 313, "styleName":"GLabel"});
            this._bg.addItem(this._conbuitTxt, {"x": 65, "y": 333, "styleName":"GLabel"});
            this._bg.addItem(this._info, {"x": 25, "y": 355, "htmlText": HTMLUtil.addColor(Language.getStringByParam(57584, "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(Language.getString(57549), "#00ff00") + "</a></u>"), GlobalStyle.color1)});
            return;
        }

        public /* override */ updateInfo(arg1: SkillInfo): void
        {
            _skillMapData = arg1;
            _skill = _skillMapData.tSkill;
            this.createDetailInfo();
            this._detailPanel.updateData(_skillMapData);
            var loc1=_skillMapData.levelMax ? HTMLUtil.addColor(Language.getString(20682), "#00ff00") : HTMLUtil.addColor(Language.getString(20683), "#ff0000");
            this._skillName.text = _skillMapData.tSkill.skillName;
            if (_skillMapData.learned) 
            {
                this._skillLevel.htmlText = Language.getString(20684) + _skillMapData.tSkill.skillLevel + loc1;
            }
            else 
            {
                this._skillLevel.htmlText = Language.getString(20684) + "0" + loc1;
            }
            if (!this._skillItem) 
            {
                this._skillItem = new SkillItem();
                this._bg.addItem(this._skillItem, {"x": 18, "y": 13});
            }
            this._skillItem.data = _skillMapData;
            this._skillItem.toolTipDataFunction = this.getToolTipData;
            this.updateCondition();
            return;
        }

        public /* override */ updateCondition(): void
        {
            if (!_skillMapData) 
            {
                return;
            }
            var loc1="";
            loc1 = _skillMapData.nextSkill.guildSchoolLevel + Language.getString(20685);
            if (_skillMapData.nextSkill.guildSchoolLevel > Cache.instance.guild.getStructureLevel(EGuildStructureType.convert(EGuildStructureType._EGuildSchool))) 
            {
                this._buildLevel.htmlText = HTMLUtil.addColor(loc1, "#ff1414");
            }
            else 
            {
                this._buildLevel.htmlText = HTMLUtil.addColor(loc1, "#6DFF00");
            }
            loc1 = _skillMapData.nextSkill.needGuildContribution.toString();
            if (Cache.instance.guild.myGuildInfo) 
            {
                if (_skillMapData.nextSkill.needGuildContribution > Cache.instance.guild.myGuildInfo.contribution) 
                {
                    this._conbuitTxt.htmlText = HTMLUtil.addColor(loc1, "#ff1414");
                }
                else 
                {
                    this._conbuitTxt.htmlText = HTMLUtil.addColor(loc1, "#6DFF00");
                }
            }
            else 
            {
                this._conbuitTxt.htmlText = HTMLUtil.addColor(loc1, "#ff1414");
            }
            return;
        }

        /* internal  */getToolTipData(arg1: SkillItem): ToolTipInfo
        {
            return (arg1.data as SkillInfo).getToolTipInfo();
        }

        /* internal */ /* var */_skillItem: SkillItem;

        /* internal */ /* var */_bg: ModuleBg;

        /* internal */ /* var */_skillName: GLabel;

        /* internal */ /* var */_skillLevel: GLabel;

        /* internal */ /* var */_detailPanel: SkillDetailPanel;

        /* internal */ /* var */_buildLevel: GLabel;

        /* internal */ /* var */_conbuitTxt: GLabel;

        /* internal */ /* var */_info: Object /* flash.text.TextField */;
    }
